<?php

/**
 * This is the model class for table "UserActivation".
 *
 * The followings are the available columns in table 'UserActivation':
 * @property integer $id
 * @property integer $userId
 * @property string $email
 * @property string $code
 * @property string $created
 *
 * The following are the available relations in the table 'UserActivation':
 * @property User $user
 */
class UserActivation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className the model class name.
	 * @return UserActivation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'UserActivation';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		return array(
			array('id, userId, email, code', 'required'),
			array('id, userId', 'numerical', 'integerOnly'=>true),
			array('code', 'length', 'max'=>255),
			array('email', 'email'),
			array('email, created', 'safe'),
			array('id, userId, code, created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		return array(
			'user'=>array(self::BELONGS_TO, 'User', 'userId'),
		);
	}

	/**
	 * @return array attached behaviors.
	 */
	public function behaviors()
	{
		return array(
			'ext.auditbehavior.AuditBehavior',
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => Yii::t('label','Id'),
			'userId' => Yii::t('label','User'),
			'code' => Yii::t('label','Code'),
			'created' => Yii::t('label','Created'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		$criteria=new CDbCriteria;

		$criteria->compare('t.id',$this->id);
		$criteria->compare('t.userId',$this->userId);
		$criteria->compare('t.code',$this->code,true);
		$criteria->compare('t.created',$this->created,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}